home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1990 / Sep 90 / MacApp.Tech$ 9⁄14⁄90 / 1988-TPasswordText-Sep90 < prev    next >
Encoding:
Text File  |  1991-03-06  |  3.7 KB  |  120 lines  |  [TEXT/GEOL]

  1. Item    3399298                         14-Sept-90        09:41PDT
  2.  
  3. From:   MUYSVASOVIC                     ACE - Jean-Denis Muys-Vasovic
  4.  
  5. To:     DK0026                          DKD - Purup Electronics,IDV
  6.         MACAPP.TECH$                    MacApp Technical
  7.  
  8. cc:     EURO.DTS                        ACE - Dev Tech Supt Europe
  9.  
  10. Sub:    TPasswordText
  11.  
  12. Peter, Dear All,
  13.  
  14. Following the current thread on a password edit text, here is a solution I
  15. propose widely. It seems rather self-contained: the only reference in your code
  16. to the TPasswordText class should be to prevent linker stripping. To use it,
  17. you just have to specify "TPasswordText" as the TEditText class name in
  18. ViewEdit. The interesting piece is in IRes which calls INHERITED GetText. I
  19. would like to hear your comments about the validity of this heresy. At least
  20. SELF.GetText would be actually incorrect. Any suggestion?
  21.  
  22. Create a subclass of TEditText like:
  23.  
  24. TYPE
  25.     TPasswordText = OBJECT(TEditText)
  26.         fPassword: Str255;
  27.         PROCEDURE TPasswordText.IPasswordText( itsSuperView : TView;
  28.                             itsLocation, itsSize: VPoint;
  29.                             itsMaxChars: INTEGER);
  30.         PROCEDURE TPasswordText.IRes( itsDocument : TDocument;
  31.             itsSuperView : TView; VAR itsParams : Ptr ); OVERRIDE;
  32.         PROCEDURE TPasswordText.KeyEventToComponents(VAR info: EventInfo);
  33.                                                         OVERRIDE;
  34.         PROCEDURE TPasswordText.GetText(VAR theText: Str255); OVERRIDE;
  35.         PROCEDURE TPasswordText.SetText(VAR theText: Str255;
  36.             redraw: BOOLEAN); OVERRIDE;
  37.     END;
  38.  
  39.  
  40. The implementation could look like (segmentation omitted):
  41.  
  42. CONST
  43.     chObscurChar = '•';         { or '' or whatever }
  44.     kSpaceVirtualCode = $31;
  45.  
  46. PROCEDURE ObscurString(VAR S: Str255);
  47.  
  48.     VAR
  49.         i: INTEGER;
  50.  
  51.     BEGIN
  52.     FOR i:=1 TO Length(S) DO
  53.         S[i] = chObscurChar;
  54.     END;
  55.  
  56. PROCEDURE TPasswordText.IPasswordText( itsSuperView : TView;
  57.                             itsLocation, itsSize: VPoint;
  58.                             itsMaxChars: INTEGER);
  59.  
  60.     BEGIN
  61.     IEditText(itsSuperView, itsLocation, itsSize, itsMaxChars);
  62.     END;
  63.  
  64. PROCEDURE TPasswordText.IRes( itsDocument : TDocument; itsSuperView : TView;
  65.             VAR itsParams : Ptr ); OVERRIDE;
  66.  
  67.     VAR
  68.         temp: Str255;
  69.  
  70.     BEGIN
  71.     INHERITED IRes( itsDocument, itsSuperView, itsParams );
  72.     INHERITED GetText(temp);
  73.     SELF.SetText(temp, kDontRedraw);
  74.     END;
  75.  
  76. PROCEDURE TPasswordText.GetText(VAR theText: Str255); OVERRIDE;
  77.  
  78.     BEGIN
  79.     theText := SELF.fPassword;
  80.     END;
  81.  
  82.  
  83. PROCEDURE TPasswordText.SetText(VAR theText: Str255;
  84.             redraw: BOOLEAN); OVERRIDE;
  85.  
  86.     VAR
  87.         temp: Str255;
  88.  
  89.     BEGIN
  90.     SELF.fPassword := theText;
  91.     temp := theText;
  92.     ObscurString(temp);
  93.     INHERITED SetText(temp, kDontRedraw);
  94.     END;
  95.  
  96.  
  97. PROCEDURE TPasswordText.KeyEventToComponents(VAR info: EventInfo); OVERRIDE;
  98.  
  99.     BEGIN
  100.     INHERITED KeyEventToComponents( info );
  101.     WITH info, thePEvent^ DO
  102.         IF (what = keyDown) | (what = autoKey) THEN
  103.             CASE theCharacter OF
  104.                 chEnter, chReturn, chTab: { handle as usual }
  105.                 chBackSpace: { completely erase string (see HI guidelines) }
  106.                     SELF.SetText( '', kRedraw);
  107.                 OTHERWISE   { just hides the character }
  108.                     BEGIN
  109.                     SELF.fPassword[0] := CHR(Length(SELF.fPassword) + 1);
  110.                     SELF.fPassword[Length(SELF.fPassword)] := theCharacter;
  111.                     theCharacter := chObscurChar;
  112.                     theKeyCode := kSpaceVirtualCode;
  113.                     message := ORD(theCharacter) + theKeyCode * 256;
  114.                     END;
  115.             END;
  116.     END;
  117.  
  118.  
  119.  
  120.